package com.fdb.efp.nls.api.rest.sed.pages;

import com.fdb.basic.framework.core.constant.DataRuleType;
import com.fdb.basic.framework.core.constant.PubConstant;
import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.core.util.StringUtil;
import com.fdb.basic.framework.web.controller.AbstractController;
import com.fdb.cdp.pboc.service.facade.CreditQueryDetailService;
import com.fdb.cdp.pboc.service.vo.CreditQueryDetailVO;
import com.fdb.efp.e4a.service.facade.SRoleDataRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 
  * TODO 征信查询信息明细
  * @author wanglihua
  * @since 2019年5月27日 上午10:13:52
  * @version 1.0
 */
@RestController
@RequestMapping("/api")
public class CreditQueryDetailController extends AbstractController {
	
	@Autowired
	@Qualifier("creditQueryDetailService")
	private CreditQueryDetailService creditQueryDetailService;

	@Autowired
	@Qualifier("sRoleDataRuleService")
	private SRoleDataRuleService sRoleDataRuleService;

	/**
	 * 列表数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/pboc/query/infos", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<CreditQueryDetailVO>> queryCreditQueryDetail(@RequestBody CreditQueryDetailVO vo) {
		List<CreditQueryDetailVO> outputVo = null;
		Map<String,String> dataRuleTypeMap = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
		vo.setPrdCodebyBaseInfo(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PRD_CODE));
		DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PERMIS_TYPE));
		setUserInfoToVO(vo);
		if (!StringUtil.isNullorBank(vo.getExportFlag()) && "exp".equals(vo.getExportFlag())) {
			switch (dataRuleType) {
				case Owner:
					outputVo = creditQueryDetailService.queryAllOwnerExp(vo);
					break;
				case CurrOrg:
					outputVo = creditQueryDetailService.queryAllCurrOrgExp(vo);
					break;
				case CurrDownOrg:
					outputVo = creditQueryDetailService.queryAllCurrDownOrgExp(vo);
					break;
				case CurrOwnerPrd:
					outputVo = creditQueryDetailService.queryAllCurrOwnerPrdExp(vo);
					break;
				default:
					outputVo = creditQueryDetailService.queryAllOwnerExp(vo);
					break;
			}
		} else if (StringUtil.isNullorBank(vo.getExportFlag())){
			// 根据权限方案调用不同的方案进行数据查询
			switch (dataRuleType) {
				case Owner:
					outputVo = creditQueryDetailService.queryAllOwner(vo);
					break;
				case CurrOrg:
					outputVo = creditQueryDetailService.queryAllCurrOrg(vo);
					break;
				case CurrDownOrg:
					outputVo = creditQueryDetailService.queryAllCurrDownOrg(vo);
					break;
				case CurrOwnerPrd:
					outputVo = creditQueryDetailService.queryAllCurrOwnerPrd(vo);
					break;
				default:
					outputVo = creditQueryDetailService.queryAllOwner(vo);
					break;
			}
		}
		return getResponseData(outputVo);
	}
}
